// src/test/java/com/bookmanager/util/DatabaseTest.java
package com.bookmanager.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class DatabaseTest {
    public static void main(String[] args) {
        try {
            Connection conn = DatabaseUtil.getConnection();
            System.out.println("✅ 数据库连接成功！");

            // 测试查询用户表
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as count FROM users");
            if (rs.next()) {
                System.out.println("✅ 用户表记录数: " + rs.getInt("count"));
            }

            // 测试具体用户查询
            rs = stmt.executeQuery("SELECT * FROM users WHERE user_id = '1001'");
            if (rs.next()) {
                System.out.println("✅ 找到管理员用户: " + rs.getString("username"));
                System.out.println("✅ 密码: " + rs.getString("password"));
                System.out.println("✅ 角色: " + rs.getString("role"));
            }

            DatabaseUtil.close(conn, stmt, rs);
        } catch (Exception e) {
            System.out.println("❌ 数据库连接失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}